package com.woniu.service.impl;

import com.woniu.mapper.EmpMapper;
import com.woniu.pojo.Emp;
import com.woniu.pojo.EmpExample;
import com.woniu.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
@Service
@Transactional
public class EmpServiceImpl implements EmpService {
    @Autowired
    EmpMapper empMapper;
    @Override
    public List<Emp> empList() {
        return empMapper.selectByExample(null);
    }
    @Override
    public Emp getOneEmp(Integer empno) {
        return empMapper.selectByPrimaryKey(empno);
    }

    @Override
    public void save(Emp emp) {
        empMapper.insert(emp);
    }

    @Override
    public void delEmp(Integer empo) {
    empMapper.deleteByPrimaryKey(empo);
    }

    @Override
    public void updateEmp(Emp emp) {
    empMapper.updateByPrimaryKey(emp);
    }

    @Override
    public List<Emp> empSelect(Emp emp) {
        System.out.println(emp+"1111");
        System.out.println(emp.getEname());
        EmpExample empExample=new EmpExample();
        EmpExample.Criteria criteria=empExample.createCriteria();
        if(emp.getEname()!=null&&!emp.getEname().equals("")){
            System.out.println(emp.getEname());
            criteria.andEnameLike("%"+emp.getEname()+"%");
        }
        if (emp.getJob()!=null&&!emp.getJob().equals("")){
            System.out.println(emp.getJob());
            criteria.andJobLike("%"+emp.getJob()+"%");
        }
        return empMapper.selectByExample(empExample);
    }

    @Override
    public void delSelect(Integer[] empnos) {
        EmpExample empExample=new EmpExample();
        List<Integer> list= Arrays.asList(empnos);
        empExample.createCriteria().andEmpnoIn(list);
        empMapper.deleteByExample(empExample);
    }
}
